package com.itqf.service.impl;

import com.itqf.dao.AddressDao;
import com.itqf.dao.impl.AddressDaoImpl;
import com.itqf.entity.Address;
import com.itqf.service.AddressService;

import java.sql.SQLException;
import java.util.List;

public class AddressServiceImpl implements AddressService {
    @Override
    public List<Address> findAllAddressByUserno(int userno) throws SQLException {
        AddressDao addressDao = new AddressDaoImpl();
        List<Address> addresses = addressDao.selectAddressesByUserno(userno);
        return addresses;
    }

    @Override
    public void saveAddress(Address address) throws SQLException {
        AddressDao addressDao = new AddressDaoImpl();
        addressDao.insertAddress(address);
    }

    @Override
    public void deleteAddressByAid(String aid) throws SQLException {
        AddressDao addressDao = new AddressDaoImpl();
        addressDao.deleteAddressByAid(aid);
    }

    @Override
    public void astAddressDefaultByAid(String aid, int userno) throws SQLException {
        AddressDao addressDao = new AddressDaoImpl();
        addressDao.updateAddressToDefault(aid);
        addressDao.updateAddressToCommons(aid,userno);
    }

    @Override
    public void updateAddress(Address address) throws SQLException {
        AddressDao addressDao = new AddressDaoImpl();
        addressDao.updateAddress(address);
    }

}
